<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>demo</title>
    <script type="text/javascript" src="../vue.js"></script>
</head>

<body>
    <div id="app">
        <h1>{{count}}</h1>
        <button @click="add">直接累加</button>
        <button @click="decrement($event)">每次累减</button>
        <button @click="addN(2,$event)">每次累加2</button>
    </div>
</body>
<script type="text/javascript">
    Vue.config.productionTip = false
    const vm = new Vue({
        el: "#app",
        data() {
            return{
                count: 0
            }
        },
        methods:{
            add(e) {
          this.count++;
        },
        /* 如果使用当前函数的时候,加括号了,则需要在参数中传递固定字符 $event 在事件函数中使用形参接受,这个值就是event事件对象 */
        decrement(e) {
          this.count--;
        },
        addN(n, e) {
          this.count += n;
        }
        }
    })
</script>

</html>